package com.lixin.smartclassroom.ui.home.tab1.activity

import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.getmyclassdetail
import com.lixin.smartclassroom.api.joinclass
import com.lixin.smartclassroom.databinding.ActivityInviteMessageBinding
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.commonDialog
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.loadRound
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.start
import com.lixinkeji.extension.toast
import com.lixinkeji.extension.visible

/**
 * Description 班级邀请
 * Author: lwc
 * Date:2023/12/9 14:50
 */
class InviteMessageAct : BaseActivity<ActivityInviteMessageBinding>() {
    override fun getViewBinding() = ActivityInviteMessageBinding.inflate(layoutInflater)

    override fun topBarHide() = true
    override fun startPadding() = false
    override fun title() = "班级邀请"
    private var fwcode = ""
    private var classid = ""
    private var inviteDate = ""
    private var inviteName = ""

    override fun iniView() {
        binding.apply {
            classid = getIntentString("classid")
            inviteDate = getIntentString("inviteDate")
            inviteName = getIntentString("inviteName")
            scopeNetLife {
                val baseBean = getmyclassdetail(classid)
                if (baseBean.result == "0") {
                    fwcode = baseBean.fwcode!!
                    ivQrCode.loadRound(baseBean.image!!)
                    tvContent.text = inviteName + "邀请你加入" + "" + baseBean.title
                    tvInviteCode.text = "班级码：" + baseBean.fwcode
                    tvInviteTime.text = inviteDate
                    when(baseBean.ifjoin){
                        "1"->{
                            btnJoin.visible()
                            btnGoClass.gone()
                        }
                        else->{
                            btnJoin.gone()
                            btnGoClass.visible()
                        }
                    }
                } else {
                    toast(baseBean.resultNote.toString())
                }
            }
        }
    }


    override fun onClick() {
        binding.apply {
            ivBack.onClick {
                finish()
            }
            btnJoin.onClick {
                scopeNetLife {
                    val baseBean = joinclass(fwcode)
                    if (baseBean.result == "0") {
                        commonDialog(
                            "加入成功",
                            "您已经成功加入班级名称",
                            cancel = "返回首页",
                            sure = "去班级",
                            onSure = {
                                start(ClassDetailAct::class.java){
                                    putExtra("classid",classid)
                                }

                            })


                    }else{
                        toast(baseBean.resultNote.toString())
                    }
                }

            }
            btnGoClass.onClick {
                start(ClassDetailAct::class.java){
                    putExtra("classid",classid)
                }
            }

        }
    }

}